<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对象响应式示例 - Vue 3 reactive</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            background-color: #f0f8ff;
        }
        #app {
            text-align: center;
            padding: 30px;
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        h1 {
            color: #4a9eff;
            margin-bottom: 20px;
        }
        h3 {
            color: #333;
            font-size: 24px;
            margin-bottom: 10px;
        }
        p {
            color: #666;
            font-size: 18px;
            margin-bottom: 20px;
        }
        button {
            padding: 10px 20px;
            font-size: 16px;
            background-color: #4a9eff;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        button:hover {
            background-color: #357abd;
        }
    </style>
</head>
<body>
    <div id="app">
        <h1>对象响应式示例</h1>
        <h3>{{ name }} Lv.{{ level }}</h3>
        <p>技能列表：{{ hero.skills.join('、') }}</p>
        <button @click="levelUp">打怪升级</button>
    </div>

    <script>
        // 定义Hero接口
        const Hero = {
            name: '',
            level: 0,
            skills: []
        };

        // 创建Vue应用
        const app = Vue.createApp({
            setup() {
                // 创建响应式对象
                const hero = Vue.reactive({
                    name: 'Vue 法师',
                    level: 1,
                    skills: ['火球术']
                });

                // 安全解构（保持响应）
                const { name, level } = Vue.toRefs(hero);

                // 升级函数
                const levelUp = () => {
                    level.value++;
                    if (level.value === 3) hero.skills.push('冰冻术');
                };

                // 返回模板中使用的数据和方法
                return {
                    hero,
                    name,
                    level,
                    levelUp
                };
            }
        });

        // 挂载应用
        app.mount('#app');
    </script>
</body>
</html>